const getMeterLastData = require('../../libs/Redis/GetMeterLastData');
const moment = require('moment');
async function mergeData(meterData, matchDevice) {
    if (matchDevice && matchDevice !== '') {
        let todayStr = moment().format('YYYY-MM-DD');
        let matchDeviceKey = `river-course-d-${matchDevice}-1-${todayStr}`;
        let matchDeviceDataStr = await getMeterLastData(matchDeviceKey);
        if (matchDeviceDataStr) {
            let matchDeviceData = JSON.parse(matchDeviceDataStr);
            let currentTime = matchDeviceData.currentTime;
            let diffMinutes = moment().diff(moment(currentTime), 'minutes');
            if (diffMinutes < 10) {
                if (matchDeviceData.currentSpeed) meterData.currentSpeed = matchDeviceData.currentSpeed;
                if (matchDeviceData.insFlow) meterData.insFlow = matchDeviceData.insFlow;
            }
        }
    }
    return meterData;
}

exports.mergeData = mergeData